package com.qfedu.service.impl;

import com.qfedu.entity.RoleEntity;
import com.qfedu.mapper.RolePojoMapper;
import com.qfedu.pojo.RolePojo;
import com.qfedu.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Service
public class RoleServiceimpl implements RoleService {
    @Autowired
    private RolePojoMapper rolePojoMapper;

    @Override
    public List<RolePojo> queryAllRole() {
        List<RolePojo> rolePojos = rolePojoMapper.queryAllRole();
        return rolePojos;
    }

    @Override
    public List<RolePojo> queryRoleList(RoleEntity roleEntity) {
        List<RolePojo> rolePojos = rolePojoMapper.queryRoleList(roleEntity);
        return rolePojos;
    }

    @Override
    public Boolean doAddRole(RoleEntity roleEntity) {
        Boolean aBoolean = rolePojoMapper.insertRole(roleEntity);
        if (!aBoolean){
            return false;
        }
        Boolean flag = rolePojoMapper.bindAuthWithRole(roleEntity);
        if (!flag){
            return  false;
        }
        return true;
    }

    @Override
    public List<RolePojo> queryauthbyid(RoleEntity roleEntity) {
        return rolePojoMapper.queryauthbyid(roleEntity);
    }

    @Override
    public Boolean editRole(RoleEntity roleEntity) {
        //更新角色
        Boolean aBoolean = rolePojoMapper.updateRole(roleEntity);
        if (!aBoolean){
            return false;
        }
        //解绑角色权限
        Boolean flag = rolePojoMapper.untying(roleEntity.getRid());
        //绑定角色
        Boolean aBoolean1 = rolePojoMapper.bindAuthWithRole(roleEntity);
        if (!aBoolean1){
            return false;
        }
        return true;
    }

    @Override
    public Boolean deleteRoleById(String ridstr) {
        ridstr="("+ridstr+")";
        Boolean aBoolean = rolePojoMapper.deleteRoleById(ridstr);
        return aBoolean;
    }


}
